package com.chendongyang.www.dao;//进行管理员对停车位和充电口的管理（增加或删除）
import com.chendongyang.www.po.chargingStation;
import com.mysql.cj.jdbc.Driver;
import com.chendongyang.www.po.parkingstation;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

public class adding {
    public  int insert(ArrayList<chargingStation> list,int number) throws SQLException {
        //进行充电站信息的增加（充电位的增加）
        int line=0;
        for(int i=0;i<number;i++) {
        DriverManager.registerDriver(new Driver());
        Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
            String sql = "insert into charging values (?,?,0);";
            PreparedStatement preparedStatement = root.prepareStatement(sql);
            preparedStatement.setString(1, list.get(i).getChargeS());
            preparedStatement.setString(2, list.get(i).getChargeB());
            line = line + preparedStatement.executeUpdate();
            preparedStatement.close();
            root.close();
        }
        return line;
    }
    public  int delete(ArrayList<chargingStation> list,int number) throws SQLException {
        //对充电位的删除
        int line=0;
        for(int i=0;i<number;i++) {
            DriverManager.registerDriver(new Driver());
            Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
            String sql = "delete from charging where 充电口=? and 充电位=? ;";
            PreparedStatement preparedStatement = root.prepareStatement(sql);
            preparedStatement.setString(1, list.get(i).getChargeS());
            preparedStatement.setString(2, list.get(i).getChargeB());
            line = line + preparedStatement.executeUpdate();
            preparedStatement.close();
            root.close();
        }
        return line;
    }
    public  int insert1(ArrayList<parkingstation> list,int number) throws SQLException {
        //进行停车位的增加
        int line=0;
        for(int i=0;i<number;i++) {
            DriverManager.registerDriver(new Driver());
            Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
            String sql = "insert into stoping values (?,?,0);";
            PreparedStatement preparedStatement = root.prepareStatement(sql);
            preparedStatement.setString(1, list.get(i).getParkingS());
            preparedStatement.setString(2, list.get(i).getParkingB());
            line = line + preparedStatement.executeUpdate();
            preparedStatement.close();
            root.close();
        }
        return line;
    }
    public  int delete1(ArrayList<parkingstation> list,int number) throws SQLException {
        //进行停车位的部分删除
        int line=0;
        for(int i=0;i<number;i++) {
            DriverManager.registerDriver(new Driver());
            Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
            String sql = "delete from stoping where 停车口=? and 停车位=? ;";
            PreparedStatement preparedStatement = root.prepareStatement(sql);
            preparedStatement.setString(1, list.get(i).getParkingS());
            preparedStatement.setString(2, list.get(i).getParkingB());
            line = line + preparedStatement.executeUpdate();
            preparedStatement.close();
            root.close();
        }
        return line;
    }
    public  int insert2(String station,String bit,String time) throws SQLException {
        //进行充电预约的增加
        int line=0;
            DriverManager.registerDriver(new Driver());
            Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
            String sql = "insert into 充电预约 values (?,?,?,0);";
            PreparedStatement preparedStatement = root.prepareStatement(sql);
            preparedStatement.setString(1, station);
            preparedStatement.setString(2, bit);
            preparedStatement.setString(3,time);
            line = line + preparedStatement.executeUpdate();
            preparedStatement.close();
            root.close();
        return line;
    }
    public  int insert3(String station,String bit,String time) throws SQLException {
        //进行充电预约的增加
        int line=0;
        DriverManager.registerDriver(new Driver());
        Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
        String sql = "insert into 停车预约 values (?,?,?,0);";
        PreparedStatement preparedStatement = root.prepareStatement(sql);
        preparedStatement.setString(1, station);
        preparedStatement.setString(2, bit);
        preparedStatement.setString(3,time);
        line = line + preparedStatement.executeUpdate();
        preparedStatement.close();
        root.close();
        return line;
    }
}
